package com.xhdx.map;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapTest {
    
    private static ConcurrentHashMap<Integer, String> mapConcurrent = new ConcurrentHashMap<Integer, String>();
    private static HashMap<Integer, String> map = new HashMap<Integer, String>();
    public static void main(String[] args) {
        Thread t1 = new Thread("Thread1"){
            @Override
            public void run() {
                for (int i = 0; i < 20; i++) {
                    //map.put(i, String.valueOf(i));
                    mapConcurrent.put(i, String.valueOf(i));
                }
            }
        };
        
        Thread t2 = new Thread("Thread2"){
            @Override
            public void run() {
                for (int i = 20; i < 40; i++) {
                    //map.put(i, String.valueOf(i));
                    mapConcurrent.put(i, String.valueOf(i));
                }
            }
        };
        
        t1.start();
        t2.start();
        for (int i = 0; i < 40; i++) {
            //System.out.println("map:"+i + "=" + map.get(i));
            System.out.println(";mapConcurrent:"+i + "=" + mapConcurrent.get(i));
        } 
    }
}